package com.msti.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.msti.entity.Student;
import com.msti.service.StudentDAO;
import com.msti.service.StudentDAOImpl;

/**
 * Servlet implementation class UpdateProfile
 */
public class UpdateProfile extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateProfile() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String type = request.getParameter("type");
		String updateDetail = request.getParameter("updateDetail");
		StudentDAO studentDAO = new StudentDAOImpl();
		Student student = new Student();
		
		if(type.equals("NICNO")){
			student = studentDAO.getStudentByNIC(updateDetail);
		}else if(type.equals("PassportNo")){
			student = studentDAO.getStudentByPassport(updateDetail);
		}else/*type.equals("CDCNO")*/{
			student = studentDAO.getStudentByCDC(updateDetail);
		}
		request.setAttribute("student", student);
		RequestDispatcher requestDispatcher = request.getRequestDispatcher("update.jsp");
		requestDispatcher.forward(request, response);
	}

}
